<!--  -->
<template>
    <div>

        <van-form @submit="onSubmit">

            <!-- 头 -->
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ nFromdata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号:</span>
                    <span class="titletext">{{ nFromdata.pmInsId }}</span>
                </div>
            </div>

            <div class="mt10" style="display: flex; border-bottom: 1px solid #ebedf0">
                <div class="blue_item"></div>
                <span class="font15" style="display: flex; line-height: 33px; margin-left: 5px; flex: 1">商机信息</span>
            </div>

            <van-field readonly required name="businessName" :value="fromdata.businessName" label="商机名称:"
                label-width="5em" />
            <van-field readonly required name="businessId" :value="fromdata.businessId" label="商机编码:" label-width="5em" />
            <van-field readonly required name="customerName" :value="fromdata.customerName" label="集团名称:"
                label-width="5em" />
            <van-field readonly required name="customerCode" :value="fromdata.customerCode" label="集团编号:"
                label-width="5em" />
            <van-field readonly required name="city" :value="fromdata.city" label="地市:" label-width="3em" />
            <van-field readonly required name="counties" :value="fromdata.counties" label="县区:" label-width="3em" />
            <van-field readonly required name="industry" :value="fromdata.industry" label="行业:" label-width="3em" />
            <van-field readonly required name="projectAmount" :value="fromdata.projectAmount" label="预算金额（万元）:"
                label-width="9em" />
            <van-field readonly required name="businessRank" :value="fromdata.businessRank" label="商机分级:"
                label-width="5em" />
            <van-field readonly required name="managerName" :value="fromdata.managerName" label="客户经理姓名:"
                label-width="7em" />
            <van-field readonly required name="managerTel" :value="fromdata.managerTel" label="客户经理电话:" label-width="7em" />
            <van-field readonly required autosize type="textarea" rows="1" name="buildContent"
                :value="fromdata.buildContent" label="建设内容:" label-width="5em" />


            <!-- 成员信息 -->
            <div class="spline"></div>
            <div class="mt10" style="display: flex; border-bottom: 1px solid #ebedf0">
                <div class="blue_item"></div>
                <span class="font15" style="display: flex; line-height: 33px; margin-left: 5px; flex: 1">成员信息</span>
            </div>
            <memberItem :member-list="fromdata.salePreMemberModel"></memberItem>


            <!-- 跳转意见 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#60a9ec; display: inline-block;width:100%;border: 0px solid #60a9ec;border-radius: 15px 0px 0px 15px;
            padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>


            <!-- 流转下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext"
                    style="display: inline-block; width: 100%; border: 0px solid #60a9ec">{{ buttonTitle }}</van-button>
            </div>
        </van-form>


        <!-- 当前办理人 -->
        <div v-if="showHistory" class="spline"></div>
        <van-field readonly center v-if="showHistory" label="当前办理人:" label-width="5.5em" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <div class="spline"></div>
        <div id="opinion" class="mt10" style="display: flex; border-bottom: 1px solid #ebedf0">
            <div class="blue_item"></div>
            <span class="font15" style="display: flex; line-height: 33px; margin-left: 5px; flex: 1">审批意见</span>
        </div>

        <div style="padding-bottom: 42px">
            <div v-if="approveList.length > 0" class="swrap" style="width: 100%">
                <div class="spiece_flex" v-for="(item, index) in approveList" :key="index">
                    <div class="vertical-a-t display-ib" style="width: 25px">
                        <i v-if="index == 0" class="iconfont icon-current font16 color-red2"></i>
                        <i v-if="index > 0" class="iconfont icon-yiban font16 color-theme"></i>
                        <div v-if="index != approveList.length - 1" class="optionline"></div>
                    </div>

                    <div class="vertical-a-t display-ib" style="width: calc(100%)">
                        <div style="white-space: nowrap">
                            <span class="color-theme font14">{{ item.producerName || "暂无" }}:</span>
                            <span class="color-2 font14">{{ item.content || "暂无" }}</span>
                        </div>

                        <div class="mt05 color-8" style="display: flex; align-items: baseline">
                            <div class="display-ib vertical-a-t font12" style="margin-top: 2px; width: 100%">
                                {{ item.companyName + ' - ' + item.departmentName || "暂无" }}
                            </div>

                            <div class="display-ib vertical-a-t font12 text-r" style="
                  margin-left: 10px;
                  margin-top: 2px;
                  text-align: right;
                  width: 100%;
                ">
                                {{ item.modifiedTime || "暂无" }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div v-else>
                <div class="color-9 font12 text-c">暂无数据</div>
            </div>
        </div>
    </div>
</template>


<script>

import memberItem from "@/views/sztdzj/sztdzjDetail/memberItem.vue";
import { mapGetters } from "vuex";
import { Notify, Toast } from "vant";
import { openFileUrl } from "@/store/openFile";
import util from "@/assets/js/public";
import {
    getSZTDZJFormDetail,
    findSalePreTeamModelBySalePreTeamId,
    getWfOptMags,
    getWfLinkTracks,
} from "@/api/dictapi";


export default {
    data() {
        return {
            fromdata: {},
            nFromdata: {},
            mFromdata: {},

            canEdit: false,
            params: this.$route.query,
            todotype: false,
            toRead:false,
            approveList: [],
            fileList: [],
            fileindex: 0,
            showHistory: false,
            historydata: {},
            zhenbieData: {},

            buttonTitle: '流转下一步',
            canToNext: true,
        };
    },

    computed: {

        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },

    //生命周期--创建完成
    created() {
        if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
        console.log("1111111",this.params.wfnid+"AAAAAA")
        if (this.params.todoType == "1") {
            this.todotype = true;
        } else if (this.params.todoType == "2") {
            this.showHistory = true;
        }else if (this.params.todoType == "3") {
            this.toRead = true;
        }

        if (this.params.location == 'dict.start') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持该环节,请至PC端办理';
        }

        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
        memberItem,
    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {

        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push({
                name: "fileview",
                query: {
                    openFileUrl: openFileUrl(value),
                },
            });
        },

        getdetail() {
            Toast.loading({ message: "加载中", forbidClick: false });
            getSZTDZJFormDetail(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.nFromdata = result.data.data;
                }

                this.getDecisionMakingByPmInsId(result.data.data.projectInformationId);
            })

            getWfOptMags(Object.assign(this.params), {
                userName: this.user.userName,
            }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                this.approveList = result.data.data.reverse();
            })

            if (this.showHistory) {

                getWfLinkTracks(Object.assign(this.params), {
                    userName: this.user.userName,
                }).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                        Notify(result.message);
                        return;
                    }
                    if (result.data.data) {
                        //数据过滤，并生成新的数组
                        this.historydata = result.data.data.filter(
                            (item) => item.CURRENTSTATE == 10
                        )[0];
                        if (this.historydata) {
                            if (this.historydata.MANAGER) {
                                this.showHistory = true;
                            } else {
                                this.showHistory = false;
                            }
                        } else {
                            this.showHistory = false;
                        }
                    } else {
                        this.showHistory = false;
                    }
                })
            }
        },

        getDecisionMakingByPmInsId(value) {
            findSalePreTeamModelBySalePreTeamId(
                Object.assign(this.params, { userName: this.user.userName, salePreTeamId: value })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                if (result.data.data) {
                    this.fromdata = result.data.data;
                }
            });
        },

        onSubmit() {

            //提交流转
            console.log("传给递交页面:", this.params)
            console.log("formDataformData", JSON.stringify(this.fromdata));
            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = this.fromdata;
            formSendData.id = this.nFromdata.id;
            formSendData.pmInsId = this.nFromdata.pmInsId;
            formSendData.processType = this.params.pmInsType
            formSendData.workItemId = this.params.workItemId;
            this.params.pmInsType = this.params.pmInsType

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };

            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };

            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                     "notificationId":this.params.todoType==3?this.params.wfnid:""
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormProject$api$startSubmitProcess',
                    
                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }));
            this.$router.push({
                name: "srqrsubmit"
            });
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
</style>